import { request, config } from 'utils'
import * as commonService from 'utils/services'

const { api: { contractOrders, salesContractOrders } } = config

/**
 *
 * @param params
 * @returns {Promise<*>}
 */
export async function query(params = {}) {
  params.apiBaseUrl = `${contractOrders}`
  return commonService.commonQuery(params)
}

/**
 *
 * @param params
 * @returns {Promise<*>}
 * @待确认订单
 */
export async function queryToconfirmOrderList(params = {}) {
  params.apiBaseUrl = `${contractOrders}/toConfirm`
  return commonService.commonQuery(params)
}

/**
 *
 * @param params
 * @returns {Promise<*>}
 */
export async function changeList(params = {}) {
  params.apiBaseUrl = `${contractOrders}/change`
  return commonService.commonQuery(params)
}

/**
 *
 * @param id
 * @returns {Promise<*>}
 */
export async function show(id) {
  const url = `${contractOrders}/detail/${id}`
  return request({ url: url, method: 'GET' })
}

/**
 *
 * @param id
 * @param version
 * @returns {Promise<*>}
 */
export async function pay(id, version) {
  const url = `${contractOrders}/${id}/pay4unpaid/${version}`
  return request({ url: url, method: 'POST' })
}
export async function payBatch(param) {
  const url = `${contractOrders}/pay4UnpaidBatch`
  return request({ url: url, method: 'POST', data: { param } })
}

/**
 * 取消合同
 * @param id
 * @param version
 * @returns {Promise<*>}
 */
export async function cancel(id, version) {
  const url = `${contractOrders}/${id}/cancelContractOrder/${version}`
  return request({ url: url, method: 'POST' })
}

/**
 * 生产中的合同订单查询列表
 * @param {*} params
 */
export async function contractListInProduction(params = {}) {
  params.apiBaseUrl = `${contractOrders}`
  params.interfaceName = 'contractListInProduction';
  return commonService.commonQuery(params)
}
/**
 * 根据合同号查询ID
 * @param {*} params
 */
export async function findByContractNum(params = {}) {
  const url = `${contractOrders}/contractId/${params.num}`
  return request({ url: url, method: 'POST' })
}

/**
 * 获取合同的物流信息
 * @param id
 * @returns {Promise<*>}
 */
export async function tms(id) {
  const url = `${salesContractOrders}/${id}/tms`
  return request({ url: url, method: 'GET' })
}

/**
 * 获取合同的安装信息
 * @param id
 * @returns {Promise<*>}
 */
export async function ins(id) {
  const url = `${salesContractOrders}/${id}/ins`
  return request({ url: url, method: 'GET' })
}
/**
 * 分润
 */
export async function divided(params) {
  const url = `${contractOrders}/divided`
  return request({ url: url, data:params,method: 'POST' })
}
